﻿#if MYSQL
using Dapper;
using DapperExtensions.MySQLExt;
#endif
#if ORACLE
using DapperExtensions.OracleExt;
#endif
#if SQLSERVER
using DapperExtensions.SqlServerExt;
#endif

using EasyIot.Model;
using System.Collections.Generic;
using System.Data;

namespace EasyIot.Repository
{
    public class BaseRepositoryExt
    {
        public static DbContext dbContext = new DbContext();
 
        /// <summary>
        /// 通过sql查询数据
        /// </summary>
        public static DataTable Query(string sql)
        {
            DataTable dt = new DataTable();

            using (var conn = dbContext.GetConnection())
            {
                dt.Load(conn.ExecuteReader(sql));
            }
            return dt;
        }
        
        /// <summary>
        /// 通过sql更新数据
        /// </summary>
        public static int Excute(string sql)
        {
            using (var conn = dbContext.GetConnection())
            {
                return conn.Execute(sql);
            }
        }
    }
}
